package practice;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 整理扑克牌
 */
public class Packcards {

    private static List<Integer> shunziList = new ArrayList<>();

    static {
        shunziList.add(3);
        shunziList.add(4);
        shunziList.add(5);
        shunziList.add(6);
        shunziList.add(7);
        shunziList.add(8);
        shunziList.add(9);
        shunziList.add(10);
        shunziList.add(11);
        shunziList.add(12);
        shunziList.add(13);
        shunziList.add(14);
    }

    private static enum Card {
        J("J",11),
        Q("Q",12),
        K("K",13),
        A("A",14);

        private String mark;

        private int val;

        Card(String mark,Integer val) {
            this.mark = mark;
            this.val = val;
        }

        public static String getMarkByVal(int val) {
            String mark = String.valueOf(val);
            for (Card card : Card.values()) {
                if (card.val == val) {
                    mark = card.mark;
                    break;
                }
            }
            return mark;
        }

        public static int getValByMark(String mark) {
            int value = 0;
            try {
               value = Integer.parseInt(mark);
            }catch (Exception e) {}

            if (value != 0) {
                return value;
            }

            for (Card card : Card.values()) {
                if (card.mark.equals(mark)) {
                    value = card.val;
                    break;
                }
            }
            return value;
        }
    }

    private static int mapToInt(String str) {
        return Card.getValByMark(str);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            // 存储输入的元素和频次
            Map<Integer, Integer> frequenceMap = new TreeMap<>();
            List<Integer> inputs = Arrays.stream(sc.nextLine().split(" "))
                    .map(Packcards::mapToInt)
                    .filter(shunziList::contains)
                    .collect(Collectors.toList());

            inputs.forEach(e -> frequenceMap.put(e, frequenceMap.getOrDefault(e,0)+1));
            List<Integer> sortedInput = inputs.stream()
                    .distinct()
                    .sorted()
                    .collect(Collectors.toList());

            boolean foundStraight = false;

            for (int i = 0; i < sortedInput.size(); i++) {
                int current = sortedInput.get(i);
                int length = 1;
                int expected = current+1;

                while (frequenceMap.get(expected) != null && frequenceMap.get(expected) > 0) {
                    length++;
                    expected++;
                }

                if (length >= 5) {
                    foundStraight = true;
                    for (int k = i; k < i+length; k++) {
                        System.out.print(Card.getMarkByVal(sortedInput.get(k)) + " ");
                        frequenceMap.put(sortedInput.get(k),frequenceMap.getOrDefault(sortedInput.get(k),0) -1);
                    }
                    System.out.println();
                }
            }

            if (!foundStraight) {
                System.out.println("No");
            }
        }
    }
}
